package nl.infodation.emr.utility;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

public final class ConfigurationReader{

	private static ConfigurationReader configContent;

	//Variable contain file name and value of file
	private final Map<String, HashMap<String, String>> properties = new HashMap<String, HashMap<String, String>>();

	private ConfigurationReader(){}

	public static synchronized ConfigurationReader getPropertyUtil() {
		if (configContent == null) {
			configContent = new ConfigurationReader();
		}
		return configContent;
	}
	
	private Map<String, String> loadProperty(final String fileName) throws IOException {
		if (!properties.containsKey(fileName)) {
			final Properties props = new Properties();
			final HashMap<String, String> mapProperties = new HashMap<String, String>();
			InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(Constants.PROPERTY_PATH_LOCAL + fileName);
	        props.load(inputStream);
			String key = "";
			final Iterator<Object> iterator = props.keySet().iterator();
			while(iterator.hasNext()) {
				key  = iterator.next().toString();
				mapProperties.put(key, props.get(key).toString());
			}
			properties.put(fileName, mapProperties);
		}
	return properties.get(fileName);
	}
	
	public Map<String, String> loadPricingProperties() throws IOException {
		return loadProperty(Constants.PRICING_SERVICE_PROPERTY_FILE);
	}
	
	public Map<String, String> loadCommonSQLProperties() throws IOException {
		return loadProperty(Constants.COMMONSQL_PROPERTY_FILE);
	}
}
	